package com.lanou.beautifulwardrobe.contants;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.lanou.beautifulwardrobe.R;

/**
 * Created by dllo on 15/11/4.
 */
public class ToastCommom  {
    private static ToastCommom toastCommom;

    private Toast toast;

    private ToastCommom(){
    }

    public static ToastCommom createToastConfig(){
        if (toastCommom==null) {
            toastCommom = new ToastCommom();
        }
        return toastCommom;
    }

    /**
     * 显示Toast
     * @param context
     * @param root
     * @param tvString
     */

    public static Toast makeText(Context context, CharSequence text, int duration) {
        Toast result = new Toast(context);

        //获取LayoutInflater对象
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //由layout文件创建一个View对象
        View layout = inflater.inflate(R.layout.activity_toast, null);

        //实例化ImageView和TextView对象
        TextView textView = (TextView) layout.findViewById(R.id.toastText);

        textView.setText(text);

        result.setView(layout);
        result.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        result.setDuration(duration);

        return result;
    }


}
